<?php
/**
 * Jobs Display on edition mode
 *
 * @author Xavier VILAIN
 */
use Fox\Ddic\DataElement\Formater\Date;
use Fox\Html\Action\Anchor;
use Fox\Html\Stream\News;
use Fox\Html\Stream;
use Fox\Behaviors;
use Hive\Ressource;
use Hive\Ressource\Experience;
use Fox\Html\Header\Content;
use Fox\Html\Screen,Fox\Generator,Fox\Html\Button;
use Fox\Html\Block,Fox\Core\Errors;

$xview = Xview::instance();
/* @var $contact Hive\Ressource */
$contact = $xview->component('ressource', 'object');
// Customizing
$customizing = Hive\Ressource\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'ressource','act'=>'wishes'));
$rid = $xview->val('rid');

$header = new Content('wish',Msg(Hive::BUNDLE,Hive::TITLE_WISHES));
$header->add(new Button('add','?',Msg(Hive::BUNDLE,Hive::MSG_ADD_A_WISH)))
		->color(Button::COLOR_WARNING)
		->behaviors(Behaviors::action(
				Generator::url('ressource','wishes','add',array('rid' => $contact->getId())),
				true,null,null,true));

$streamHtml = null;
$first = true;
foreach($contact->wishes() as $object) {
	$wid = $object->did;
	$date = new Date();
	if($first) {
		$label = Msg(Hive::BUNDLE,Hive::MSG_CURRENT_WISH,$date->format($object->cdate));
		$first = false;
	} else {
		$label = Msg(Hive::BUNDLE,Hive::MSG_OLDER_WISH,$date->format($object->cdate));
	}
	
	// Content
	$blWish = new Block('wish_'.$wid);
	$blWish->noLegend();
	$initData = $object->getData();
	$initData['localization'] = $object->formatLocalizationTokens();
	$wishMoodLabel = $object->mood()->label();
	$title = $wishMoodLabel;
	$dateString = Fox\Utilities\Dates::dateTimeToFullString($object->udate);
	if($object->uname > 0) {
		$subTitle = Msg(Hive::BUNDLE,Hive::ON_X1_BY_X2,$dateString,Fox\User::fullName($object->uname));
	} else {
		$subTitle = Msg(Hive::BUNDLE,Hive::ON_X1,$dateString);
	}
	$texts = null;
	// Search a Job List
	if(!empty($initData['joblist'])) {
		$texts .= '<span class="fsm"><strong>'.Msg(Hive::BUNDLE,Hive::SEARCH).'</strong>:</span><p class="fsm" style="margin-bottom:0">'.$initData['joblist'].'</p>';
	}
	$texts .= '<div class="fsm">';
	$texts .= Msg(Hive::BUNDLE,Hive::SALARY_X1_X2_BONUS,$initData['targeted_salary'],$initData['targeted_bonus']);
	if(!empty($initData['company_size_type'])) {
		$texts .= ' - '.Msg(Hive::BUNDLE,Hive::COMPANY_TYPE_X1,$object->companyType()->label());
	}
	if(!empty($initData['localization'])) {
		$token = new Fox\Html\DropList\Token(array('localization','localization_'.$wid));
		$token->noLabel()->formater("\\Fox\\Common\\Localization::parse");
		$token->initialize($initData['localization']);
		$token->displayMode(Fox\Html\DropList\Token::DISPLAY_READONLY);
		$texts .= '<br>'.Msg(Hive::BUNDLE,Hive::TARGET_LOCALIZATION);
		$texts .= $token->display();
	}
	$texts .= '</div>';
	// Update
	$behaviorUpdate = new Behaviors(Behaviors::action(Generator::url('ressource','wishes','update',
								array('rid' => $rid,'wid' => $wid)),true,null,null,true));
	$behaviorUpdate->add(Behaviors::value('slink'));
	// Delete
	$behaviorDelete = new Behaviors(Behaviors::action(Generator::url('ressource','wishes','delete',
								array('inlineid' => $object->getInLineId())),true,null,null,true));
	$behaviorDelete->add(Behaviors::value('slink del'));
	
	
	$streamHtml .= '<li class="mbs pbm noteEntry uiListItem uiListLight uiListVerticalItemBorder">
				<div class="mvs fsl fwb fcb">
					<span class="uiListItemTitle">'.$title.'</span>
				</div>
				<div class="fsm fwn fcg">
					'.$subTitle.' &#8226; 
					<span class="UIActionLinks UIActionLinks_bottom">
						<a href="#" id="upd_'.$wid.'" class="'.$behaviorUpdate->serialize(array(),'').'">'.Msg(Hive::BUNDLE,Hive::UPDATE).'</a>
						 &#8226; <a href="#" id="del_'.$wid.'" class="'.$behaviorDelete->serialize(array(),'').'">'.Msg(Hive::BUNDLE,Hive::DELETE).'</a>
					</span>
				</div>
				<div class="clearfix interview-text">
					<div>
						'.$texts.'
					</div>
				</div>
			</li>';
}

if(count($contact->wishes()) > 0) {
	$html = '<ul>'.$streamHtml.'</ul>';
}
else {
	$html = '<p class="prettyprint">'.Msg(Hive::BUNDLE,Hive::MSG_NO_WISH).'</p>';
}
?>
<div>
	<div class="page-header clearfix">
		<?php echo $header->render();?>
	</div>
	<div class="contentArea">
			<?php echo $html;?>
	</div>
</div>